package com.shqcjd.yunweiyanoperator.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.shqcjd.yunweiyanoperator.R;
import com.shqcjd.yunweiyanoperator.app.AppConstant;
import com.shqcjd.yunweiyanoperator.app.MyApp;
import com.shqcjd.yunweiyanoperator.ui.base.BaseActivity;
import com.shqcjd.yunweiyanoperator.ui.base.BasePresenter;
import com.shqcjd.yunweiyanoperator.util.AppManager;
import com.shqcjd.yunweiyanoperator.util.PrefUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 设置页面
 */
public class SetActivity extends BaseActivity {

    @BindView(R.id.btn_finish)
    ImageView btnFinish;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rl_set_pwd)
    RelativeLayout rlSetPwd;
    @BindView(R.id.tv_reset)
    TextView tvReset;

    private Context mContext;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_set;
    }

    @Override
    public void init() {
        super.init();
        mContext = this;
    }

    @Override
    public void initView() {
        super.initView();
        tvTitle.setText("设置");

        int typeId = PrefUtils.getInt(mContext, PrefUtils.USER_TYPE, -1);
        if (typeId == 3) {//游客
            rlSetPwd.setVisibility(View.GONE);
        } else {
            rlSetPwd.setVisibility(View.VISIBLE);
        }
    }

    @OnClick({R.id.btn_finish, R.id.rl_set_pwd, R.id.tv_reset})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_finish:
                finish();
                break;
            case R.id.rl_set_pwd:
                Intent it = new Intent(mContext, ChangePasswordActivity.class);
                startActivity(it);
                break;
            case R.id.tv_reset:
                signOut();
                break;
        }
    }

    /**
     * 退出登录
     */
    private void signOut() {
        MyApp.the().getmAgoraAPI().logout();
        PrefUtils.setBoolean(this, PrefUtils.FIRST_LOGIN, false);
        PrefUtils.setInt(this, PrefUtils.USER_ID, -1);
        PrefUtils.setString(this, PrefUtils.USER_CODE, "");
        PrefUtils.setString(this, PrefUtils.USER_NAME, "");
        PrefUtils.setString(this, PrefUtils.PHONE_NUMBER, "");
        PrefUtils.setString(this, PrefUtils.USER_ICON, "");
        PrefUtils.setString(this, AppConstant.TOKEN_KEY, "");
        PrefUtils.setInt(this, PrefUtils.USER_TYPE, -1);
        PrefUtils.setString(this, PrefUtils.USER_ACCOUNT, "");
        PrefUtils.setString(this, PrefUtils.USER_PWD, "");
        PrefUtils.setString(this, PrefUtils.TOKEN, "");
        PrefUtils.setInt(this, PrefUtils.USER_STATE, -1);
        PrefUtils.setString(this, PrefUtils.BUSINESSId, "");
        PrefUtils.setString(this, PrefUtils.APPCODE, "");
        PrefUtils.setInt(mContext, PrefUtils.ORGANIZATION_TYPE, -1);
        PrefUtils.setString(mContext, PrefUtils.BUSINESSNAME, "");
        AppManager.getAppManager().finishAllActivity();
        Intent it = new Intent(this, LoginActivity.class);
        startActivity(it);
    }

}
